<template>
    <div class="audit-video-list" v-loading="loading">
        <div class="input-box">
            <el-input
                placeholder="请输入您要搜索的内容"
                style="width:200px;"
                @keyup.enter.native="getList"
                clearable
                v-model.trim="keyword">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
            <el-button type="primary" class="btn" @click="getList">搜索</el-button>
            <el-button type="success" class="btn" @click="goQuickCheckVideo">快速审核</el-button>
        </div>
        <div class="table-box">
            <el-table
                :data="tableData"
                border
                style="width: 100%">
                <el-table-column
                    fixed
                    prop="videoid"
                    label="id">
                </el-table-column>
                <el-table-column
                    prop="title"
                    width="180"
                    label="视频标题">
                </el-table-column>
                <el-table-column
                    width="180"
                    label="视频">
                    <template slot-scope="scope">
                        <videoBox :url="scope.row.mp4Url || scope.row.url" :time="scope.row.duration" :img="scope.row.cover"/>
                    </template>
                </el-table-column>
                <el-table-column
                    width="150"
                    label="相关游戏">
                    <template slot-scope="scope">
                        <div v-if="scope.row.gameid" @click="goGameDetail(scope.row)" class="table-btn">{{scope.row.gameName || '-'}}</div>
                        <div v-else>{{scope.row.gameName || '-'}}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="游戏状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.gameStatus === '1'" style="color:#67C23A;">已上架</span>
                        <span v-else style="color: #F56C6C;">已下架</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="话题">
                    <template slot-scope="scope">
                        <span>{{scope.row.gameTopic || '-'}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="视频类型">
                    <template slot-scope="scope">
                        <span>{{whatType(scope.row.category)}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    width="240"
                    label="用户信息">
                    <template slot-scope="scope">
                            <div>
                                <b>用户昵称：</b>
                                <img :src="scope.row.userIcon" alt="" class="user-icon">
                                <span @click="goUserDetail(scope.row.userid)" class="table-btn">{{scope.row.userName || scope.row.userid}}</span>
                            </div>
                        <div>
                            <b>用户ID：</b>
                            <span>{{scope.row.userid || '-'}}</span>
                        </div>
                        <div>
                            <b>上传时间：</b>
                            <span>{{(scope.row.createTime || '-') | timeNo0}}</span>
                        </div>
                        <div>
                            <b>已传视频数：</b>
                            <span>{{scope.row.userVideoCount || '0'}}</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="address"
                    fixed="right"
                    label="操作">
                    <template slot-scope="scope">
                        <template v-if="scope.row.auditStatus === 0">
                            <div><el-button @click="throwUserVideo(scope.row)" type="text" size="small">通过</el-button></div>
                            <div><el-button @click="beforeRefusedUser(scope.row)" type="text" size="small">驳回</el-button></div>
                            <div><el-button @click="goQuickCheckVideoItem(scope.row)" type="text" size="small">查看详情</el-button></div>
                            <!-- <div><el-button @click="beforeDelUser(scope.row, )" type="text" size="small">封禁</el-button></div> -->
                        </template>
                        <template v-else>
                            <span v-if="scope.row.auditStatus === -1">审核不通过</span>
                            <span v-if="scope.row.auditStatus === 3">已上架</span>
                        </template>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>

        <!-- 拒绝用户 -->
        <el-dialog
            class="show-refused-user-box"
            title="驳回原因"
            :close-on-click-modal="false"
            :show-close="false"
            :visible.sync="showRefusedUser"
            width="600px">
            <el-radio-group v-model="radioTxt">
                <el-radio-button class="radio-item" label="非游戏">非游戏</el-radio-button>
                <el-radio-button class="radio-item" label="质量低">质量低</el-radio-button>
                <el-radio-button class="radio-item" label="不宜展示">不宜展示</el-radio-button>
                <el-radio-button class="radio-item" label="优化标题">优化标题</el-radio-button>
                <el-radio-button class="radio-item" label="关联游戏错误">关联游戏错误</el-radio-button>
                <el-radio-button class="radio-item" label="关联视频类型错误">关联视频类型错误</el-radio-button>
                <el-radio-button class="radio-item" label="黑屏">黑屏</el-radio-button>
            </el-radio-group>
            <el-input
                ref="textarea"
                type="textarea"
                :rows="2"
                placeholder="请输入内容"
                v-model="textarea">
            </el-input>
            <span slot="footer" class="dialog-footer">
                <el-button size="mini" type="primary" @click="refusedUser">确 定</el-button>
                <el-button size="mini" @click="showRefusedUser = false">取 消</el-button>
            </span>
        </el-dialog>

        <!-- 封禁用户 -->
        <el-dialog
            title="提示"
            :close-on-click-modal="false"
            :show-close="false"
            :visible.sync="showDisableUser"
            width="30%">
            <span>确定要封禁该用户么？</span>
            <span slot="footer" class="dialog-footer">
                <el-button size="mini" type="primary" @click="delUser">确 定</el-button>
                <el-button size="mini" @click="showDisableUser = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data () {
        return {
            keyword: '',
            list: [],
            pageNum: 1,
            pageSize: this._pageSize,
            total: 0,
            loading: false,
            showRefusedUser: false, // 拒绝用户
            showDisableUser: false, // 封禁用户
            radioTxt: '非游戏',
            textarea: '',
            categoryList: []
        }
    },

    activated () {
        if (this.listParams) {
            this.keyword = this.listParams.keyword
        }
        this.getList()
    },

    created () {
        this.findVideoCategory()
    },

    watch: {
        textarea (val) {
            if (val) {
                this.radioTxt = ''
            }
        },
        radioTxt (val) {
            if (val) {
                this.textarea = ''
            }
        }
    },

    computed: {
        // 前端分页
        tableData () {
            let start = this.pageNum * this.pageSize - this.pageSize
            let end = this.pageNum * this.pageSize
            return this.list.slice(start, end)
        }
    },

    methods: {
        async getList () {
            if (this.loading) return
            this.pageNum = 1
            this.loading = true
            this.listParams = {
                pageIndex: 1,
                pageNum: 100,
                status: 0
            }
            if (this.keyword) {
                this.listParams.keyword = this.keyword
            }
            let res = await this.$http.post('/video/findGameVideos', this.listParams)
            if (res.code === '0') {
                this.list = res.data
                this.total = res.count > 100 ? 100 : res.count
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },

        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
        },

        // 页容切换
        pageChange (val) {
            this.pageNum = val
        },

        async findVideoCategory () {
            let res = await this.$http.post('/video/findVideoCategory')
            if (res.code === '0') {
                this.categoryList = res.data || []
            }
        },

        whatType (type) {
            let typeStr = '/'
            if (type) {
                this.categoryList.forEach(item => {
                    if (type === item.category) {
                        typeStr = item.name
                    }
                })
            }
            return typeStr
        },

        // 通过
        async throwUserVideo (item, status) {
            let params = {
                videoId: item.videoid,
                status: 3
            }
            let res = await this.$http.post('/video/updateGameVideoStatus', params)
            if (res.code === '0') {
                this.$message({
                    type: 'success',
                    message: '已通过'
                })
                item.auditStatus = 3
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
        },

        // 封禁用户
        beforeDelUser (item) {
            this.currentItem = item
            this.showDisableUser = true
        },

        async delUser () {
            let params = {
                userId: this.currentItem.userid
            }
            let res = await this.$http.post('/video/forbideUser', params)
            if (res.code === '0') {
                this.$message({
                    type: 'success',
                    message: '封禁成功'
                })
                this.currentItem.auditStatus = 3
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.showDisableUser = false
        },

        // 拒绝用户
        beforeRefusedUser (item) {
            this.currentItem = item
            this.showRefusedUser = true
        },

        async refusedUser () {
            if (!this.radioTxt && !this.textarea) {
                this.$message({
                    type: 'error',
                    message: '请输入或选择驳回理由!'
                })
                return
            }
            let params = {
                videoId: this.currentItem.videoid,
                status: -1,
                reason: this.radioTxt || this.textarea
            }
            let res = await this.$http.post('/video/updateGameVideoStatus', params)
            if (res.code === '0') {
                this.$message({
                    type: 'success',
                    message: '已拒绝'
                })
                this.currentItem.auditStatus = -1
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.showRefusedUser = false
        },

        // 查看视频详情
        goQuickCheckVideo () {
            this.$router.push({
                path: '/video/auditVideoDetail',
                query: {
                    keyword: this.listParams.keyword
                }
            })
        },

        // 查看视频详情
        goQuickCheckVideoItem (item) {
            this.$router.push({
                path: '/video/auditVideoDetail',
                query: {
                    keyword: this.listParams.keyword,
                    id: item.videoid
                }
            })
        },

        // 查看游戏详情
        goGameDetail (item) {
            const { href } = this.$router.resolve({
                path: '/game/gameDetail',
                query: {
                    id: item.gameid
                }
            })
            window.open(href, '_blank')
        },

        // 查看用户详情
        goUserDetail (id) {
            const { href } = this.$router.resolve({
                path: '/dataReport/userInfo',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        }
    }
}
</script>

<style lang="scss" scoped>
    .audit-video-list {
        .input-box {
            .btn {
                margin-left: 10px;
            }
        }
        .table-box {
            margin: 20px 0;
            .user-icon {
                width: 20px;
                height: 20px;
                border-radius: 50%;
                margin-right: 5px;
                vertical-align: top;
            }
            .table-btn {
                cursor: pointer;
                color: #409EFF;
                font-size: 13px;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
            .app-icon {
                width: 60px;
                height: 60px;
                > img {
                    width: 100%;
                    height: 100%;
                }
            }
        }
        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }

        .show-refused-user-box {
            .radio-item {
                border: 1px solid #DCDFE6;
                margin-right: 10px;
                margin-bottom: 10px;
                /deep/ .el-radio-button__inner {
                    border: none;
                }
            }
        }
    }
</style>
